import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';

function RouterBeforeEach() {
    var location = useLocation()
    var navigate = useNavigate()
    //监听路由变化，变更路由验证token是否存在
    var token = useSelector((state: any) => state.userInfo.token)
    useEffect(() => {
        if (!token) {
            navigate('/login')
        } else if (location.pathname == '/login') {
            navigate('/index/home')
        }
    }, [location.pathname])
    return (
        <div>

        </div>
    );
}

export default RouterBeforeEach;